/*
	Compresor Gzip
    Copyright (C) 2012 Darío López Padial 
    @bukosabino

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>
*/

/**
 @file crc32.cpp
 @brief Implementación de la Clase crc32
 @author Dario Lopez Padial
 */

#include "crc32.h" 

crc32 :: crc32() {
  unsigned long l;
	int n, k;
	for (n = 0; n < 256; n++) {
		l = static_cast <unsigned long> (n);
		for (k = 0; k < 8; k++) {
			if (l & 1) 
				l = 0xedb88320L ^ (l >> 1);
			else 
				l = l >> 1;
		}
    tabla[n] = l;
	}
  c=0xFFFFFFFF;
}

void crc32 :: Add ( unsigned char byte ) {
	c = (c>>8) ^ tabla[(c^byte)&0xFF];
}

unsigned long  crc32 :: Get( ) const {
	return c ^ 0xFFFFFFFF;
}
